import request from './request'

// ==================== 用户管理 ====================
// 获取用户列表
export function getUserList(params) {
  return request({
    url: '/admin/users',
    method: 'get',
    params
  })
}

// 添加用户
export function addUser(data) {
  return request({
    url: '/admin/user',
    method: 'post',
    data
  })
}

// 更新用户信息
export function updateUser(data) {
  return request({
    url: '/admin/user',
    method: 'put',
    data
  })
}

// 重置用户密码
export function resetUserPassword(userId, data) {
  return request({
    url: `/admin/user/${userId}/reset-password`,
    method: 'put',
    data
  })
}

// 修改用户状态
export function updateUserStatus(userId, data) {
  return request({
    url: `/admin/user/${userId}/status?status=${data.status}`,
    method: 'put'
  })
}

// 删除用户
export function deleteUser(userId) {
  return request({
    url: `/admin/user/${userId}`,
    method: 'delete'
  })
}

// 用户活动统计
export function getUserStatistics(params) {
  return request({
    url: '/admin/users/statistics',
    method: 'get',
    params
  })
}

// ==================== 挂号管理 ====================
// 获取挂号统计
export function getRegistrationStatistics(params) {
  return request({
    url: '/admin/registrations/statistics',
    method: 'get',
    params
  })
}

// 获取挂号列表
export function getRegistrationList(params) {
  return request({
    url: '/admin/registrations',
    method: 'get',
    params
  })
}

// 批量处理挂号
export function batchProcessRegistrations(data) {
  return request({
    url: '/admin/registrations/batch',
    method: 'put',
    data
  })
}

// 获取挂号费用
export function getRegistrationFees() {
  return request({
    url: '/admin/registration/fees',
    method: 'get'
  })
}

// 更新挂号费用
export function updateRegistrationFee(data) {
  return request({
    url: '/admin/registration/fee',
    method: 'put',
    data
  })
}

// ==================== 排班管理 ====================
// 获取排班统计
export function getScheduleStatistics(params) {
  return request({
    url: '/admin/schedules/statistics',
    method: 'get',
    params
  })
}

// 科室排班协调
export function getDepartmentSchedules(params) {
  return request({
    url: '/admin/schedules/departments',
    method: 'get',
    params
  })
}

// 医生工作量分析
export function getDoctorWorkload(params) {
  return request({
    url: '/admin/schedules/workload',
    method: 'get',
    params
  })
}

// 创建排班
export function createSchedule(data) {
  return request({
    url: '/admin/schedule',
    method: 'post',
    data
  })
}

// 批量创建排班
export function batchCreateSchedules(data) {
  return request({
    url: '/admin/schedules/batch',
    method: 'post',
    data
  })
}

// ==================== 就诊管理 ====================
// 就诊数据统计
export function getMedicalRecordStatistics(params) {
  return request({
    url: '/admin/medical-records/statistics',
    method: 'get',
    params
  })
}

// 医疗质量分析
export function getMedicalQualityAnalysis(params) {
  return request({
    url: '/admin/medical-records/quality',
    method: 'get',
    params
  })
}

// 就诊效率评估
export function getMedicalEfficiency(params) {
  return request({
    url: '/admin/medical-records/efficiency',
    method: 'get',
    params
  })
}

// 获取就诊记录列表
export function getMedicalRecordList(params) {
  return request({
    url: '/admin/medical-records',
    method: 'get',
    params
  })
}

// ==================== 医生管理 ====================
// 获取医生列表
export function getDoctorList(params) {
  return request({
    url: '/admin/doctors',
    method: 'get',
    params
  })
}

// 更新医生信息
export function updateDoctor(data) {
  return request({
    url: '/admin/doctor',
    method: 'put',
    data
  })
}

// 医生资质审核
export function auditDoctor(doctorId, data) {
  return request({
    url: `/admin/doctor/${doctorId}/audit`,
    method: 'put',
    data
  })
}

// 人员调配
export function transferDoctor(doctorId, data) {
  return request({
    url: `/admin/doctor/${doctorId}/transfer`,
    method: 'put',
    data
  })
}

// 医生工作统计
export function getDoctorStatistics(doctorId, params) {
  return request({
    url: `/admin/doctor/${doctorId}/statistics`,
    method: 'get',
    params
  })
}


// 添加科室
export function addDepartment(data) {
  return request({
    url: '/admin/department',
    method: 'post',
    data
  })
}

// 更新科室信息
export function updateDepartment(data) {
  return request({
    url: '/admin/department',
    method: 'put',
    data
  })
}

// 删除科室
export function deleteDepartment(departmentId) {
  return request({
    url: `/admin/department/${departmentId}`,
    method: 'delete'
  })
}

// 科室统计信息
export function getDepartmentStatistics(departmentId, params) {
  return request({
    url: `/admin/department/${departmentId}/statistics`,
    method: 'get',
    params
  })
}

// ==================== 医院信息管理 ====================
// 获取医院信息
export function getHospitalInfo() {
  return request({
    url: '/admin/hospital/info',
    method: 'get'
  })
}

// 更新医院信息
export function updateHospitalInfo(data) {
  return request({
    url: '/admin/hospital/info',
    method: 'put',
    data
  })
}

// 获取设备信息
export function getEquipmentList(params) {
  return request({
    url: '/admin/hospital/equipment',
    method: 'get',
    params
  })
}

// 添加设备
export function addEquipment(data) {
  return request({
    url: '/admin/hospital/equipment',
    method: 'post',
    data
  })
}

// 获取资源配置
export function getHospitalResources() {
  return request({
    url: '/admin/hospital/resources',
    method: 'get'
  })
}

// 获取运营数据
export function getHospitalOperations(params) {
  return request({
    url: '/admin/hospital/operations',
    method: 'get',
    params
  })
}

// ==================== 药方管理 ====================
// 药方数据审核
export function getPrescriptionAuditList(params) {
  return request({
    url: '/admin/prescriptions/audit',
    method: 'get',
    params
  })
}

// 审核药方
export function auditPrescription(prescriptionId, data) {
  return request({
    url: `/admin/prescription/${prescriptionId}/audit`,
    method: 'put',
    data
  })
}

// 批量审核药方
export function batchAuditPrescriptions(data) {
  return request({
    url: '/admin/prescriptions/batch-audit',
    method: 'put',
    data
  })
}

// 用药合理性分析
export function getPrescriptionAnalysis(params) {
  return request({
    url: '/admin/prescriptions/analysis',
    method: 'get',
    params
  })
}

// 药方统计报表
export function getPrescriptionReport(params) {
  return request({
    url: '/admin/prescriptions/report',
    method: 'get',
    params
  })
}

// 药品使用监控
export function getDrugMonitor(params) {
  return request({
    url: '/admin/prescriptions/drug-monitor',
    method: 'get',
    params
  })
}

// 获取药方详情
export function getPrescriptionDetail(prescriptionId) {
  return request({
    url: `/admin/prescription/${prescriptionId}`,
    method: 'get'
  })
}

// ==================== 药品管理 ====================
// 获取药品列表
export function getMedicineList(params) {
  return request({
    url: '/admin/medicines',
    method: 'get',
    params
  })
}

// 添加药品
export function addMedicine(data) {
  return request({
    url: '/admin/medicine',
    method: 'post',
    data
  })
}

// 更新药品信息
export function updateMedicine(data) {
  return request({
    url: '/admin/medicine',
    method: 'put',
    data
  })
}

// 删除药品
export function deleteMedicine(medicineId) {
  return request({
    url: `/admin/medicine/${medicineId}`,
    method: 'delete'
  })
}

// 药品入库
export function addMedicineStock(medicineId, data) {
  return request({
    url: `/admin/medicine/${medicineId}/add-stock`,
    method: 'post',
    data
  })
}

// 药品出库
export function reduceMedicineStock(medicineId, data) {
  return request({
    url: `/admin/medicine/${medicineId}/reduce-stock`,
    method: 'post',
    data
  })
}

// 库存预警
export function getMedicineWarnings(params) {
  return request({
    url: '/admin/medicines/warning',
    method: 'get',
    params
  })
}

// 药品库存统计
export function getMedicineStatistics(params) {
  return request({
    url: '/admin/medicines/statistics',
    method: 'get',
    params
  })
}

// 更新药品状态
export function updateMedicineStatus(medicineId, data) {
  return request({
    url: `/admin/medicine/${medicineId}/status`,
    method: 'put',
    data
  })
}

// 批量更新过期药品
export function updateExpiredMedicines() {
  return request({
    url: '/admin/medicines/update-expired',
    method: 'put'
  })
}

// ==================== 公告管理 ====================
// 获取公告列表
export function getAnnouncementList(params) {
  return request({
    url: '/business/admin/announcements',
    method: 'get',
    params
  })
}

// 发布公告
export function createAnnouncement(data) {
  return request({
    url: '/business/admin/announcement',
    method: 'post',
    data
  })
}

// 更新公告
export function updateAnnouncement(data) {
  return request({
    url: '/business/admin/announcement',
    method: 'put',
    data
  })
}

// 删除公告
export function deleteAnnouncement(announcementId) {
  return request({
    url: `/business/admin/announcement/${announcementId}`,
    method: 'delete'
  })
}

// 撤回公告
export function withdrawAnnouncement(announcementId, data) {
  return request({
    url: `/business/admin/announcement/${announcementId}/withdraw`,
    method: 'put',
    data
  })
}

// 置顶公告
export function topAnnouncement(announcementId, data) {
  return request({
    url: `/business/admin/announcement/${announcementId}/top`,
    method: 'put',
    data
  })
}

// 公告效果统计
export function getAnnouncementStatistics(announcementId) {
  return request({
    url: `/business/admin/announcement/${announcementId}/statistics`,
    method: 'get'
  })
}

// 获取公告分类
export function getAnnouncementCategories() {
  return request({
    url: '/business/admin/announcement/categories',
    method: 'get'
  })
}

// 批量操作公告
export function batchOperateAnnouncements(data) {
  return request({
    url: '/business/admin/announcements/batch',
    method: 'put',
    data
  })
}

// 获取公告模板
export function getAnnouncementTemplates() {
  return request({
    url: '/business/admin/announcement/templates',
    method: 'get'
  })
}

// ==================== 操作日志 ====================
// 获取操作日志
export function getOperationLogs(params) {
  return request({
    url: '/admin/operation-logs',
    method: 'get',
    params
  })
}

/**
 * 获取医生列表（带分页和筛选）
 * @param {Object} params - 查询参数
 * @param {string} [params.keyword] - 搜索关键词
 * @param {number} [params.departmentId] - 科室ID
 * @param {number} [params.status] - 状态
 * @param {number} [params.page=1] - 页码
 * @param {number} [params.size=20] - 每页大小
 * @returns {Promise} 返回医生列表数据
 */
export function getDoctors(params) {
  return request.get('/admin/doctors', { params })
}

/**
 * 获取医生详情
 * @param {number} doctorId - 医生ID
 * @returns {Promise} 返回医生详细信息
 */
export function getDoctorDetail(doctorId) {
  return request.get(`/admin/doctor/${doctorId}`)
}

/**
 * 添加医生
 * @param {Object} doctorData - 医生信息
 * @returns {Promise} 返回添加结果
 */
export function addDoctor(doctorData) {
  return request.post('/admin/doctor', doctorData)
}

/**
 * 删除医生
 * @param {number} doctorId - 医生ID
 * @returns {Promise} 返回删除结果
 */
export function deleteDoctor(doctorId) {
  return request.delete(`/admin/doctor/${doctorId}`)
}

// 获取仪表盘统计数据
export function getDashboardStatistics() {
  return request({
    url: '/admin/statistics',
    method: 'get'
  })
}

// 获取挂号趋势数据
export function getRegistrationTrend(days) {
  return request({
    url: '/admin/registration/trend',
    method: 'get',
    params: { days }
  })
}

// 获取科室分布数据
export function getDepartmentDistribution() {
  return request({
    url: '/admin/department/distribution',
    method: 'get'
  })
}

// 获取实时挂号数据
export function getRealtimeRegistrations() {
  return request({
    url: '/admin/registration/realtime',
    method: 'get'
  })
}

// 获取系统预警信息
export function getSystemWarnings() {
  return request({
    url: '/admin/warnings',
    method: 'get'
  })
} 